import { Body, Controller, Post, Request } from '@nestjs/common';
import { UserService } from './user.service';
import { CreateUserDto } from './dto/create-user.dto';
import { Public } from '../public/public.decorator';
import { AddFriendDto } from './dto/add-friend.dto';

@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  /**
   * 用户注册
   * @param createUserDto
   */
  @Public()
  @Post('register')
  createUser(@Body() createUserDto: CreateUserDto) {
    return this.userService.createUser(createUserDto);
  }

  /**
   * 添加好友
   * @param addFriendDto
   * @param req
   */
  @Post('add-friend')
  addFriend(@Body() addFriendDto: AddFriendDto, @Request() req: any) {
    const myMobile = req.user.mobile;
    const friendMobile = addFriendDto.mobile;
    return this.userService.addFriend(myMobile, friendMobile);
  }

  /**
   * 删除好友
   * @param addFriendDto
   * @param req
   */
  @Post('delete-friend')
  deleteFriend(@Body() addFriendDto: AddFriendDto, @Request() req: any) {
    const myMobile = req.user.mobile;
    const friendMobile = addFriendDto.mobile;
    return this.userService.deleteFriend(myMobile, friendMobile);
  }
}
